<?php
session_start();
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";

//' Elimina una categoria asociada al tecnico
$tecnico = $_REQUEST["CboSoporte"];
$medidatiempo = $_REQUEST["Cbomedida"];
$cantidadtiempo = $_REQUEST["txtcanti"];
$email = $_REQUEST["txtemail"];
$opcion = $_REQUEST["opc1"];
$secuencia = $_REQUEST["secuencia"];
$empresa = $_REQUEST["CboEmpresa"];
$area = $_REQUEST["CboArea"];
$cat1 = $_REQUEST["CboCategoria1"];
$cat2 = $_REQUEST["CboCategoria2"];
$cat3 = $_REQUEST["CboCategoria3"];
$estado = "A";
$fecha = date('d/m/Y');

$tabla = "solotb_asociar_categ_tecnico";
switch ($opcion) {
    case 2:
    //'delete
        $tipo = "DELETE";
        $strSql = "$tipo from $tabla where secuencia =" . $secuencia;
        $arrQueries = array();
        array_push($arrQueries, $strSql);
        array_push($arrQueries, crearQueryLog($tabla, $tipo, $strSql));
        $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
                $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
        //$oConexion->EjecutarQuery($strSql);
        $oConexion->EjecutarTransaccion($arrQueries);
        ?>
<script type="text/javascript">
    window.opener.location.reload();
    window.close();
</script>
        <?php
        break;
    case 4:
//'update
        $sql = "$tipo $tabla set ";
        $sql .= "cod_tecnico='$tecnico',";
        $sql .= "id_nivel1=$empresa,";
        $sql .= "id_nivel2=$area,";
        $sql .= "id_nivel3=$cat1,";
        $sql .= "id_nivel4=$cat2,";
        $sql .= "id_nivel5=$cat3,";
        $sql .= "estado='A',";
        $sql .= "tipo_medida_tiempo=$medidatiempo,";
        $sql .= "cantidad_medida_tiempo=$cantidadtiempo";
        $sql .= " where secuencia=$secuencia";

        //$ret = SoloFun_ExecQuery($sql);
        $arrQueries = array();
        array_push($arrQueries, $sql);
        array_push($arrQueries, crearQueryLog($tabla, $tipo, $sql));
        $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"],
                $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
        //$oConexion->EjecutarQuery($strSql);
        $oConexion->EjecutarTransaccion($arrQueries);
        break;
    default:
    //'insert
        $strSql = "select max(secuencia)+1 as secuencia  from solotb_asociar_categ_tecnico";
        $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
                $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);

        if(!$oConexion->EjecutarQuery($strSql)) {
            $strERROR = 1;
            $err = 0;
        }

        $MaxId = $oConexion->getData("NUM");
        $MaxId = $MaxId[0][0];
        $oConexion->Cerrar();
        $soloSQL = "select * from solotb_asociar_categ_tecnico where id_nivel1=$empresa and id_nivel2=$area and id_nivel3=$cat1 and id_nivel4=$cat2 and id_nivel5=$cat3 and cod_tecnico like '$tecnico'";
        soloFun_ExecSQL ($soloSQL,$SoloArrasocia);
        if (is_null($SoloArrasocia[0][0]))
            $ban = 1;
        else {
            $ban = 0;
            echo "esta categoria ya ha sido ingresada para este tecnico";
            return;
        }

        $tipo = "INSERT";
        $strSql = "$tipo into $tabla values (";
        $strSql .= $MaxId . ",'";
        $strSql .= $tecnico . "',";
        $strSql .= $empresa . ",";
        $strSql .= $area . ",";
        $strSql .= $cat1 . ",";
        $strSql .= $cat2 . ",";
        $strSql .= $cat3 . ",'";
        $strSql .= $estado . "','";
        $strSql .= $fecha . "',";
        $strSql .= $medidatiempo . ",";
        $strSql .= $cantidadtiempo . ")";
//'response.write(strsql)
//'response.End()
//echo $strSql;
        $arrQueries = array();
        array_push($arrQueries, $strSql);
        array_push($arrQueries, crearQueryLog($tabla, $tipo, $strSql));
        $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
                $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
        if(!$oConexion->EjecutarTransaccion($arrQueries)) {
//'	 response.write STRsqL & err.description
            $strMsg = "solotrn_asociar_tecnico_categoria.php?MiError=1&des=" . $oConexion->getErrorMessage();
        }else
            $strMsg = "solotrn_asociar_tecnico_categoria.php?MiError=0";

//echo $strMsg;
        $oConexion->Cerrar();
//    'response.redirect strMsg
        break;
}
?>
<script type="text/javascript">
    window.opener.location.reload();window.close();
</script>
<?php
include "Includes/soloFun_ShowMessages.php";
?>